/**
 * The Ship is the main player in the game, keeping track of the Captain, the
 * ItemBag and the Crew members. Ship has pace, rations, and deteriorates
 * without repair.
 */
public class Ship
{
    private int pace;
    private int rations;
    private Captain captain;
    private Crew[] crewMates = new Crew[4];
    public ItemBag inventory;

    public Ship()
    {
        captain = new Captain();
        inventory = new ItemBag();

        for (int i = 0; i < 4; i++)
            crewMates[i] = new Crew();
        pace = rations = 0;
        //temp initial number for pace
        pace = 10;
    }

    /**
     * Overloaded Constructor
     * 
     * @param pace
     * @param rations
     */
    public Ship(int pace, int rations)
    {
        this.pace = pace;
        this.rations = rations;
    }

    /**
     * Getters and Setters
     */
    public ItemBag getInventory()
    {
        return inventory;
    }
    
    public void setInventory(ItemBag inventory)
    {
         this.inventory = inventory;
    }
   //For Save/Load
    public int[] getItems(){
    	return inventory.getQuantity();
    }
    //For Save/Load
    public void setItems(int[] items){
    	this.inventory.setQuantity(items);
    }

    public int getPace()
    {
        return pace;
    }

    public void setPace(int pace)
    {
        this.pace = pace;
    }

    public int getRations()
    {
        return rations;
    }

    public void setRations(int rations)
    {
        this.rations = rations;
        //System.out.println("setRations set to: " + rations);
    }

    public void setCaptainName(String name)
    {
        captain.setName(name);
    }

    public String getCaptainName()
    {
        return captain.getName();
    }

    public void setCrewNames(String[] names)
    {
        for (int i = 0; i < 4; i++)
            crewMates[i].setName(names[i]);
    }

    public String getCrewNames()
    {
        String temp = "";
        for (int i = 0; i < 4; i++)
            temp = temp + crewMates[i].getName() + ", ";
        return temp;
    }
    public String[] getSaveCrew()
    {
    	String[] temp = new String[4];
        for (int i = 0; i < 4; i++)
            temp[i] = crewMates[i].getName();
        return temp;
    }
    public void setSaveCrew(String[] crew)
    {
        for (int i = 0; i < 4; i++)
            crewMates[i].setName(crew[i]);
    }
    
    /**
     * @return name of consumed crew mate, or empty string if all crew mates are already dead
     * NOTE: when a crew member is killed, they are marked as dead by having a name that is an empty string
     */
    public String consumeCrewMate(){
    	String name = "";
    	for(int i = 0; i<crewMates.length; i++){
    		if(crewMates[i].getName() != null){
    			name = crewMates[i].getName();
    			crewMates[i].setName(null);
    			break;
    		}
    	}
    	return name;
    }

    public void setProf(String prof)
    {
        captain.setProf(prof);
    }

    public String getProf()
    {
        return captain.getProfName();
    }
}